{extend name="admin/b2c/base" /}
{block name="resources"/}
<style  type="text/css">
.set-style{
	width:100%;
}
.set-style dl{
	width:100%;
	font-size: 0;
	/* line-height: 20px; */
	clear: both;
	padding: 0;
	margin: 0;
	border-bottom: dotted 1px #E6E6E6;
	overflow: hidden;
}
.set-style dl dt{
	font-size: 12px;
	line-height: 32px;
	vertical-align: top;
	letter-spacing: normal;
	word-spacing: normal;
	text-align: right;
	display: inline-block;
	width: 19%;
	padding: 10px 1% 10px 0;
	margin: 0;
	font-weight:normal;
}
.set-style dl dd{
	font-size: 12px;
	line-height: 32px;
	vertical-align: top;
	letter-spacing: normal;
	word-spacing: normal;
	display: inline-block;
	width: 78%;
	padding: 10px 0 10px 0;
}
.set-style dl dd input[type="text"]{
	font: 12px/20px Arial;
	color: #777;
	background-color: #FFF;
	vertical-align: top;
	display: inline-block;
	height:24px;
	line-height:24px;
	padding: 4px;
	border: 1px solid #CCC;
	outline: 0 none;
	width: 400px;
	margin:0;
}
.set-style dl dd textarea{
    font: 12px/20px Arial;
    color: #777;
    background-color: #FFF;
    vertical-align: top;
    display: inline-block;
    height: 60px;
    padding: 4px;
    border: solid 1px #CCC;
    outline: 0 none;
	width: 400px;
	margin:0;
}
.hint{
    font-size: 12px;
    line-height: 16px;
    color: #BBB;
    margin-top: 10px;
}
.set-style dl dd p img{
	border: medium none;
	vertical-align: middle;
}
.class-logo{
	background-color: #FFF;
	position: relative;
	z-index: 1;
}
.class-logo p{
	width: 200px;
	height: 60px;
	line-height: 0;
	background-color: #FFF;
	text-align: center;
	vertical-align: middle;
	display: table-cell;
	*display: block;
	overflow: hidden;
	    margin: 0 0 10px;
		border: dashed 1px #E6E6E6;
}
.class-logo p img{
	max-width: 200px;
	max-height: 60px;
	border: medium none;
	vertical-align: middle;
	margin-top: expression(60-this.height/2);
	*margin-top: expression(30-this.height/2);
}
.edit_button{
	padding-top:10px;
	padding-bottom:10px;
	padding-left:30px;
	padding-right:30px;
	background-color:#51A351;
	color:#FFF;
	margin:20px auto;
	border:none;
	display:block;
}
.error{
	font-size: 12px;
    line-height: 16px;
    color: red;
    margin-top: 10px;
	display:none;
}
.set-style dl dd p{
	margin-bottom:0;
}
</style>
 {/block}
 {block name="main"}
<div class="set-style">
	<input name="UserCode" id="category_id" type="hidden"value="{$data.category_id}">
	<dl>
		<dt>商品分类名称:</dt>
		<dd>
			<p><input name="UserCode" id="category_name" type="text" value="{$data.category_name}"> </p>
			<p class="error">请输入商品分类</p>
		</dd>
	</dl>
	<dl>
		<dt>商品分类简称:</dt>
		<dd>
			<p><input name="UserCode" id="short_name" type="text" value="{$data.short_name}" > </p>
			<p class="error">请输入商品分类简称</p>
		</dd>
	</dl>
	<dl>
		<dt>上级分类:</dt>
		<dd>
			<select name="search_type" id="pid">
				<option value="0">顶级分类</option>
				{foreach name="category_list" item="v1"}
				<option value="{$v1['category_id']}" {if condition="$data.pid eq $v1['category_id']"}selected{/if}>{$v1['category_name']}</option>
				{foreach name="v1['child_list']" item="v2"}
				<option value="{$v2['category_id']}" {if condition="$data.pid eq $v2['category_id']"}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;{$v2['category_name']}</option>
				{/foreach} {/foreach} {/foreach}
			</select>
		</dd>
	</dl>
	<dl>
		<dt>是否可见:</dt>
		<dd>
			<p>
				<input id="is_visible" type="checkbox" class="checkbox" {if condition="$data.is_visible eq 1"}checked="checked"{/if}/>
				<span class="help-inline" id="is_menuPrompt" style="display: none;"></span>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>关键字:</dt>
		<dd>
			<p><input name="" id="keywords" type="text" value="{$data.keywords}"/></p>
			<p class="error">请输入关键字</p>
			<p class="hint">用于网站搜索引擎的优化，关键字之间请用英文逗号分隔</p>
		</dd>
	</dl>
	<dl>
		<dt>排序:</dt>
		<dd>
			<p><input name="UserCode" id="sort" type="text"value="{$data.sort}"></p>
			<p class="error">请输入序号</p>
		</dd>
	</dl>
	<dl>
		<dt>图片:</dt>
		<dd>
			<div class="class-logo">
				<p>
					{if condition="$data.category_pic != ''"}
					<img id="imglogo" src="__UPLOAD__/{$data.category_pic}" >
					{else/}
					<img id="imglogo" >
					{/if}
				</p>
			</div>
			<div class="ncsc-upload-btn"> 
				<a href="javascript:void(0);">
					<span>
						<input hidefocus="true" size="1" class="input-file" name="file_upload" id="uploadImg" type="file" onchange="imgUpload(this,'logo')">
						<input type="hidden" id="logo"value="{$data.category_pic}"/>
					</span>
					<p><i class="icon-upload-alt"></i>上传图片</p>
				</a> 
			</div>
			<p class="hint"><br><span style="color:orange;">建议使用宽100像素-高100像素内的GIF或PNG透明图片；点击下方"提交"按钮后生效。</span></p>
		</dd>
	</dl>
	<dl>
		<dt>描述:</dt>
		<dd>
			<p><textarea id="description">{$data.description}</textarea></p>
			<p class="error">请输入模块描述</p>
		</dd>
	</dl>
	<button class="edit_button" onclick="updateGoodsCategoryAjax();">提交</button>
</div>
{include file="admin/b2c/openDialog" /}
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
	/**
	 *图片上传
	 */
	function imgUpload(event) {
		var fileid = $(event).attr("id");
		var str = $(event).next().attr("id");
		fileCommonUpload("UPLOAD_URL", fileid,"__UPLOAD__",str);
	}
	/**
	*模块输入信息验证
	*/
	function verify( category_name,short_name, keywords, sort, description){
		if(category_name == ''){
			$("#category_name").parent().next().show();
			$("#category_name").focus();
			return false;
		}else{
			$(".error").hide();
		}
		if(short_name == ''){
			$("#short_name").parent().next().show();
			$("#short_name").focus();
			return false;
		}
		else{
			$(".error").hide();
		}
		if(keywords == ''){
			$("#keywords").parent().next().show();
			$("#keywords").focus();
			return false;
		}else{
			$(".error").hide();
		}
// 		if(sort == ''){
// 			$("#sort").parent().next().show();
// 			return false;
// 		}else{
// 			$(".error").hide();
// 		}
// 		if(description == ''){
// 			$("#description").parent().next().show();
// 			return false;
// 		}else{
// 			$(".error").hide();
// 		}
		return true;
	}
	/**
	* 修改模块
	*/
	function updateGoodsCategoryAjax() {
		var category_id = $("#category_id").val();
		var category_name = $("#category_name").val();
		var short_name = $("#short_name").val();
		var pid = $("#pid").val();
		var keywords = $("#keywords").val();
		var sort = $("#sort").val();
		var description = $("#description").val();
		var category_pic = $("#logo").val();
		if($("#is_visible").prop("checked")){
			var is_visible = 1;
		}else{
			var is_visible = 0;
		}
		if(verify(category_name,short_name, keywords, sort, description)){
			$.ajax({
				type : "post",
				url : "ADMIN_MAIN/Goods/updateGoodsCategory",
				data : {
					'category_id' : category_id,
					'category_name' : category_name,
					'pid' : pid,
					'keywords' : keywords,
					'sort' : sort,
					'description' : description,
					'is_visible' : is_visible,
					"category_pic" : category_pic,
					"short_name" : short_name
				},
				success : function(data) {
					if (data["code"] > 0) {
						showMessage('success', data["message"],'ADMIN_MAIN/Goods/goodsCategoryList');
					}else{
						showMessage('error', data["message"]);
					}
				}
			});
		}
	}
</script>
{/block}